package com.linln.wtp.controller.points;

import com.linln.common.utils.SessionUtil;
import com.linln.component.wtpshiro.annotation.UserLoginToken;
import com.linln.modules.points.service.PointsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : pengliang
 * @version V1.0
 * @Project: timo
 * @Package com.linln.wtp.controller.points
 * @Descriptio /**
 * @Project: timo
 * @Package com.linln.wtp.controller.points
 * @Description: TODO
 * @date Date : 2020年12月11日 16:35
 */
@RestController
@RequestMapping("points")
@Slf4j
public class PointsController {
    @Autowired
    private PointsService pointsService;

    @UserLoginToken
    @GetMapping
    public Map<String, Object> getPoints(@RequestParam(required = false, defaultValue = "0", value = "pageNum") Integer pageNum, @RequestParam(required = false, defaultValue = "10") Integer limit, Integer status) {
        Map<String, Object> map;
        try {
            map = pointsService.getPointsByType(pageNum, limit, SessionUtil.getUserId(), status);
        } catch (Exception e) {
            log.error(e.getMessage());
            map = new HashMap<>();
            map.put("code", 500);
            map.put("msg", "获取积分列表失败");
        }
        return map;
    }
}
